﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLNhaSach;
using System.Data;

namespace DataAccessLayer
{
    public class PhieuThuTienDAL
    {
        DataService ds = new QLNhaSach.DataService();
        public double GetTongTienCuaKhachHangTraTrongThang(string thang, string nam, int maKhachHang)
        {
            double kq = 0;
            try
            {
                String sql = "SELECT SUM(PT_SOTIENTHU) FROM PHIEUTHU, KHACHHANG WHERE";
                sql += " PT_MAKHACHHANG = KH_MAKHACHHANG AND";
                sql += " PT_MAKHACHHANG = " + maKhachHang.ToString() + " AND";
                sql += " YEAR(PT_NGAYTHU)='" + nam + "' AND MONTH(PT_NGAYTHU) ='" + thang + "'";
                kq = double.Parse(ds.ExcuteQuery(sql).ToString());
            }
            catch (Exception)
            {
                throw;
            }
            return kq;

        }
        public DataTable layDanhSachPhieuThu()
        {
            DataTable DT = new DataTable();
            try
            {
                string sql = "SELECT * FROM PHIEUTHU";
                DT = ds.GetTable(sql);
            }
            catch (Exception)
            {
                throw;
            }
            return DT;
        }
    }
}
